const quoteService = require("../services/quoteService");
const result = require("../utils/result");

module.exports = {
  // 获取一条数据
  async getOneQuote(req, res) {
    try {
      const quote = await quoteService.getOneQuote();
      return res.json(result.success(quote));
    } catch (error) {
      return res.json(result.fail(error.message));
    }
  },

  // 创建一条数据
  async createQuote(req, res) {
    try {
      const quote = await quoteService.createQuote(req.body);
      return res.json(result.success(quote));
    } catch (error) {
      return res.json(result.fail(error.message));
    }
  },

  // 删除一条数据
  async deleteQuote(req, res) {
    try {
      const id = req.params.id;
      const quote = await quoteService.deleteQuote(id);
      return res.json(result.success(quote));
    } catch (error) {
      return res.json(result.fail(error.message));
    }
  },

  //   获取所有数据
  async getAllQuote(req, res) {
    try {
      const quotes = await quoteService.getAllQuote();
      return res.json(result.success(quotes));
    } catch (error) {
      return res.json(result.fail(error.message));
    }
  },
};
